import * as NS from "../../Common/NetServices";
import { IsNull } from "../../TYLibrary/Common/GlobalExtend";
import { Wx_XSPPage, V_Member_Coupon } from "../../Common/Entitys";
import { Log } from "../../TYLibrary/System/Logger";
import { Wx_PageData, WXDataClassRuntimeDecorator, T_ShareInfo } from "../../Common/EntityBase";

@WXDataClassRuntimeDecorator()
class CouponPageData extends Wx_PageData {
    public Member_Coupon_TList: Array<V_Member_Coupon> = [];
    public Member_Coupon_FList: Array<V_Member_Coupon> = [];
    public Member_Coupon_TCount: number = 0;
    public Member_Coupon_FCount: number = 0;
    public flag: boolean = false;
    public tabIndex: number = 0;
    public selectdeFlag: boolean = false;
}

class CouponPage extends Wx_XSPPage {
    public Data: CouponPageData = new CouponPageData();

    /**
     * 初始化页面信息
     * @param {any} options
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async InitData(options: any): Promise<void> {
        try {
            let InfoFlag = false;
            let Info = options.Info;
            if (Info == "selectde") {
                InfoFlag = true;
            }
            this.Data.selectdeFlag = InfoFlag;

            let t = new Array<V_Member_Coupon>();
            let f = new Array<V_Member_Coupon>();

            this.App.Member_CouponFList = await NS.QueryMemberCoupon(false);
            this.App.Member_CouponTList = await NS.QueryMemberCoupon(true);

            if (this.App.Member_CouponTList != null) {
                this.App.Member_CouponTList.ForEach((item, index) => {
                    let c = item as V_Member_Coupon;
                    console.log("///////////////////////////", c.STARTTIME, c.COUPONINFO.STARTDATE);
                    let stard = new Date(c.COUPONINFO.STARTDATE);
                    let endd = new Date(c.COUPONINFO.ENDDATE);
                    c.STARTDAY =
                        stard.getFullYear() +
                        "." +
                        (stard.getMonth() + 1) +
                        "." +
                        stard.getDate() +
                        "   00:00";
                    c.ENDDAY =
                        endd.getFullYear() +
                        "." +
                        (endd.getMonth() + 1) +
                        "." +
                        endd.getDate() +
                        "    23:59";

                    t.push(c);
                });
            }

            if (this.App.Member_CouponFList != null) {
                this.App.Member_CouponFList.ForEach((item, index) => {
                    let c = item as V_Member_Coupon;
                    let stard = new Date(c.COUPONINFO.STARTDATE);
                    let endd = new Date(c.COUPONINFO.ENDDATE);
                    c.STARTDAY =
                        stard.getFullYear() +
                        "." +
                        (stard.getMonth() + 1) +
                        "." +
                        stard.getDate() +
                        "  00:00";
                    c.ENDDAY =
                        endd.getFullYear() +
                        "." +
                        (endd.getMonth() + 1) +
                        "." +
                        endd.getDate() +
                        "   23:59";
                    f.push(c);
                });
            }
            console.log(t);
            this.Data.Member_Coupon_TList = t;
            this.Data.Member_Coupon_FList = f;
            this.Data.Member_Coupon_TCount = this.App.Member_CouponTList.length;
            this.Data.Member_Coupon_FCount = this.App.Member_CouponFList.length;
            this.Data.flag = false;
            this.Data.tabIndex = 0;
            this.Data.ApplyChange(this);
        } catch (e) {
            console.log(e);
        }
    }

    /**
     *
     * @param {*} e
     * @memberof CouponPage
     */
    public ConditionHandler(e: any): void {
        if (this.Data.flag == false) {
            this.Data.flag = true;
        } else {
            this.Data.flag = false;
        }
        this.Data.ApplyChange(this);
    }
}

Page(new CouponPage());
